//
//  HomeSearchFoodVC.m
//  Tour
//
//  Created by hesiyao on 16/3/10.
//  Copyright © 2016年 张中烨. All rights reserved.
//

#import "HomeSearchFoodVC.h"

@interface HomeSearchFoodVC () <UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) BaseTableView *tableview;
@property (nonatomic, strong) SearchFoodView *foodView; /**< 整个视图 */
@property (nonatomic, assign) CGFloat totalHeight; /**< 总高度 */
@property (nonatomic, strong) NSString *titleImageStr;
@property (nonatomic, strong) NSString *titleNameStr;
@property (nonatomic, strong) NSString *detailIntrolduceStr;
@property (nonatomic, strong) NSString *detailAddressStr;
@property (nonatomic, strong) NSString *detailRoutiueStr;
@property (nonatomic, strong) NSString *detailPhoneStr;
@property (nonatomic, strong) NSString *detailTimeStr;
@property (nonatomic, strong) NSString *detailTicketStr;
@end

@implementation HomeSearchFoodVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self createSubviews];
    [self dataHandler];
    
}

- (void)createSubviews
{
    //初始化tableview
    self.tableview = [[BaseTableView alloc] initWithFrame:FRAME];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    [_tableview registerClass:[FoodCell class] forCellReuseIdentifier:@"cell"];
    [self.view addSubview:_tableview];
}
//数据处理
- (void)dataHandler
{
    NSString *url = [NSString stringWithFormat:@"http://open.qyer.com/qyer/footprint/poi_detail?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&oauth_token=89dd34fbffaaa72503b4baa7a9d02812&page=1&poi_id=%@",self.cellid];
    NSString *str = @"&screensize=640&track_app_channel=App%2520Store&track_app_version=6.8.3&track_device_info=iPhone%25204%28ChinaMobile%2CChinaUnicom%29&track_deviceid=CDA3EEEB-61BF-473E-AFFF-32B6332C9BBF&track_os=ios%25207.1.2&track_user_id=7328550&v=1";
    [AFNModel GETWithHandler:[NSString stringWithFormat:@"%@%@",url,str] completion:^(id result) {
        /**< 导航栏标题 */
        self.navigationItem.title = result[@"data"][@"chinesename"];
        
        CGSize size = CGSizeMake(SCREEN_WIDTH - 20, 1000);
        //计算高度
        CGFloat introlduceHeight = [UIView heightWith:result[@"data"][@"introduction"] size:size];
        CGFloat addressHeight = [UIView heightWith:result[@"data"][@"address"] size:size];
        CGFloat routiueHeight = [UIView heightWith:result[@"data"][@"wayto"] size:size];
        CGFloat timeHeight = [UIView heightWith:result[@"data"][@"opentime"] size:size];
        NSLog(@"%f, %f, %f, %f", introlduceHeight,addressHeight, routiueHeight,timeHeight);
        //总高度
        self.totalHeight = introlduceHeight + addressHeight + routiueHeight + timeHeight + SCREEN_HEIGHT / 4 + SCREEN_HEIGHT / 20 * 9;
        
        
        self.foodView = [[SearchFoodView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, _totalHeight) WithdetailIntrolduce:result[@"data"][@"introduction"] WithDetailAddress:result[@"data"][@"address"] WithDetailRoutiue:result[@"data"][@"wayto"] WithDetailTime:result[@"data"][@"opentime"]];
        _foodView.userInteractionEnabled = YES;
        //赋值
        [_foodView.titleImage sd_setImageWithURL:[NSURL URLWithString:result[@"data"][@"photo"]]placeholderImage:[UIImage imageNamed:@"zhanweitu.jpg"]];
        _foodView.titleName.text = result[@"data"][@"chinesename"];
        _foodView.detailIntroduce.text = result[@"data"][@"introduction"];
        _foodView.detailAddress.text = result[@"data"][@"address"];
        _foodView.detailRoutiue.text = result[@"data"][@"wayto"];
        _foodView.detailPhone.text = result[@"data"][@"phone"];
        _foodView.detailTime.text = result[@"data"][@"opentime"];
        _foodView.detailTicket.text = result[@"data"][@"price"];
        _tableview.tableHeaderView = _foodView;
        [_tableview reloadData];
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    FoodCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
